package com.jbit.examSystem.controller;

import com.github.pagehelper.PageHelper;
import com.jbit.examSystem.param.PageParam;
import com.jbit.examSystem.pojo.*;
import com.jbit.examSystem.pojo.Class;
import com.jbit.examSystem.service.ClassService;
import com.jbit.examSystem.service.ExamResultService;
import com.jbit.examSystem.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("examResult")
public class ExamResultController {
    @Autowired
    private ExamService examService;
    @Autowired
    private ExamResultService examResultService;
    @Autowired
    private ClassService classService;

    @RequestMapping("list")
    @ResponseBody
    public TableDataInfo list(ResultCDT cdt, PageParam page){
        TableDataInfo respData = new TableDataInfo();
        if(cdt.getGradeId() == null){
            return respData;
        }
        try {
            PageHelper.startPage(page.getPageNum(), page.getPageSize(), true, true, false);
            List<GradeInfo> infos = examResultService.getInfo(cdt.getGradeId());

            respData.succeed(infos, 0);
        } catch (Exception e){
            respData.setCode(500);
            e.printStackTrace();
        }
        return respData;
    }
    @RequestMapping("getExamNameByClassId")
    @ResponseBody
    public List<Exam> getExamNameByClassId2(Integer classId){
        List<Exam> exams = examService.getExamNameByClassId(classId);
        return exams;
    }

    @RequestMapping("list2")
    @ResponseBody
    public TableDataInfo list2(ResultCDT cdt, PageParam page){
        TableDataInfo respData = new TableDataInfo();
        if(cdt.getClassId() == null){
            return respData;
        }
        try {
            PageHelper.startPage(page.getPageNum(), page.getPageSize(), true, true, false);
            List<ClassInfo> infos = examResultService.getInfo2(cdt.getClassId());

            respData.succeed(infos, 0);
        } catch (Exception e){
            respData.setCode(500);
            e.printStackTrace();
        }
        return respData;
    }
    @RequestMapping("getClassByGradeId")
    @ResponseBody
    public List<Class> getExamNameByClassId(Integer gradeId){
        List<Class> classes = classService.getClassByGradeId(gradeId);
        return classes;
    }
}
